/**
 * 
 */
package com.arx.graphics;

import com.arx.common.Common;
import com.arx.graphics.flyweight.ANIM_HANDLE;
import com.arx.interactive.InteractiveObject;
import com.arx.time.Time;

/**
 * @author Donald
 *
 */
public class Poly {
	/** the singleton instance. */
	private static Poly	instance;
	/**
	 * Gets the one and only instance of {@link Poly}.
	 * @return {@link Poly}
	 */
	public static Poly getInstance() {
		if (Poly.instance == null) {
			Poly.instance = new Poly();
		}
		return Poly.instance;
	}
	//*************************************************************************************
	// Memorizes information for animation to animation smoothing interpolation
	//*************************************************************************************
	public void AcquireLastAnim(final InteractiveObject io) {
		if (io != null
				&& io.getAnimationLayer(0) != null
				&& io.getAnimationLayer(0).getCur_anim() != null
				&& io.getAnimationLayer(1) != null
				&& io.getAnimationLayer(1).getCur_anim() != null
				&& io.getAnimationLayer(2) != null
				&& io.getAnimationLayer(3).getCur_anim() != null
				&& io.getAnimationLayer(3) != null
				&& io.getAnimationLayer(3).getCur_anim() != null) {
			// Stores Frametime and number of vertex for later interpolation
			float f = Common.getInstance().checkUnsignedLongValue(
						Time.getInstance().getFrameTime());
			io.setLastanimtime((long) f);
			io.setNb_lastanimvertex(1);
		}
	}

	//*************************************************************************************
	// Declares an Animation as finished.
	// Usefull to update object true position with object virtual pos.
	//*************************************************************************************
	public void FinishAnim(final InteractiveObject io, 
			final ANIM_HANDLE eanim) {
		if (io != null && eanim != null) {
			if (io.getAnimationLayer(0) != null
					&& io.getAnimationLayer(0).getCur_anim() != null
					&& eanim.equals(io.getAnimationLayer(0).getCur_anim())) {
			// Only layer 0 controls movement...
				// do whatever is needed to finish movement for the io
				/*
				io->move.x = io->lastmove.x = 0;
				io->move.y = io->lastmove.y = 0;
				io->move.z = io->lastmove.z = 0;
				*/
			}
		}
	}
}
